package ru.ifmo.croak.sample;

import ru.ifmo.croak.api.Message;
import ru.ifmo.croak.api.PostService;
import ru.ifmo.croak.util.CroakFactory;

import java.util.UUID;

/**
 * Sample implementation of Post UI component that does not have any UI, but just posts a sample message.
 *
 * @author Roman Elizarov
 */
public class PostUI implements Runnable {
    public static void main(String[] args) {
        new PostUI("ui.post").run();
    }

    private final String name;

    public PostUI(String name) {
        this.name = name;
    }

    public void run() {
        String postProviderName = CroakFactory.getInstance().getProperty(name + ".provider");
        PostService post = CroakFactory.getInstance().getImplementation(PostService.class, postProviderName);
        Message message = new Message();
        message.setAuthor("sample");
        message.setId(UUID.randomUUID());
        message.setTime(System.currentTimeMillis());
        message.setText("Sample text");
        post.postMessage(message);
    }
}
